
<template>
  <div>
    <el-button @click="jump2GoodsAdd" type="success" plain>添加商品</el-button>
    <el-table :data="goodsList" style="width: 100%">
      <el-table-column type="index"></el-table-column>
      <el-table-column prop="goods_name" label="商品名称" width="180"></el-table-column>
      <el-table-column prop="goods_price" label="商品价值" width="180"></el-table-column>
      <el-table-column prop="goods_number" label="商品数量"></el-table-column>
      <el-table-column prop="add_time" label="创建时间">
        <template slot-scope="scope">
          <span>{{ scope.row.add_time | dateFilter }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" type="primary" plain icon="el-icon-edit"></el-button>
          <el-button size="mini" type="danger" plain icon="el-icon-delete"></el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
// 引入vue
/* eslint-disable */
import Vue from "vue";
import moment from "moment";

// 注册一个过滤器
Vue.filter("dateFilter", res => {
  return moment(res).format("YYYY-MM-DD HH:mm:ss");
});

export default {
  data() {
    return {
      goodsList: [
        {
          goods_name: "2016-05-02",
          goods_price: "王小虎",
          goods_number: "上海市普陀区金沙江路 1518 弄",
          add_time: "2019"
        }
      ]
    };
  },
  created() {
    this.loadGoodsList();
  },
  methods: {
    /**
     * 加载商品数据
     */
    async loadGoodsList() {
      let res = await this.$axios.get("goods", {
        params: {
          query: "",
          pagenum: 1,
          pagesize: 4
        }
      });
      console.log(res);
      this.goodsList = res.data.data.goods;
    },
    /**
     * 跳转到 添加商品页面
     */
    jump2GoodsAdd() {
      this.$router.push("/goods-add");
    }
  }
};
</script>

<style>
</style>
